import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the ShopbusPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-shopbus',
  templateUrl: 'shopbus.html',
})
export class ShopbusPage {
  shopbus:any=[];
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi:BusiProvider,public native:NativeProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ShopbusPage');
  }

  ionViewDidEnter(){
    this.getMyShopBus();
  }

  getMyShopBus(){
    this.busi.getMyShopBus().subscribe(
      data=>{
        this.shopbus = data.myshopbus;
      },
      error=>{

      }
    );
  }


  productdetail(prodid){
    this.navCtrl.push("ProductdetailPage",{prodid:prodid});
  }
  buy(){
    let body = {
      shopbus:this.shopbus
    }
    this.busi.buyFromShopBus(body).subscribe(
      data=>{
        this.native.showToast("购买成功 ！");
        this.getMyShopBus();
      },error=>{}
    )
  }

}
